package dataBase;
import db_properties_path.*;
import java.sql.*;
import java.util.*;
import dbTool.*;


public class MEMBER extends DBconnection2 {
public MEMBER(SetPath set){
super(set);
}
public MEMBER(){
super(new DefaultSetPath());
}
/** Auto Increasment */
/** Primary Key */
/** INT UNSIGNED ; java.lang.Long */private int memberid;
/** VARCHAR ; java.lang.String */private String m_name;
/** VARCHAR ; java.lang.String */private String m_phone;
/** VARCHAR ; java.lang.String */private String m_nickname;
/** VARCHAR ; java.lang.String */private String m_email;
/** VARCHAR ; java.lang.String */private String m_password;
public int getMemberid(){
return  memberid;
}
public void setMemberid(int memberid){
this.memberid= memberid;
}

public String getM_name(){
return  m_name;
}
public void setM_name(String m_name){
this.m_name= m_name;
}

public String getM_phone(){
return  m_phone;
}
public void setM_phone(String m_phone){
this.m_phone= m_phone;
}

public String getM_nickname(){
return  m_nickname;
}
public void setM_nickname(String m_nickname){
this.m_nickname= m_nickname;
}

public String getM_email(){
return  m_email;
}
public void setM_email(String m_email){
this.m_email= m_email;
}

public String getM_password(){
return  m_password;
}
public void setM_password(String m_password){
this.m_password= m_password;
}

public interface fn{
String TABLE_NAME = "MEMBER";
String PK = "memberid";
String memberid="memberid";
String m_name="m_name";
String m_phone="m_phone";
String m_nickname="m_nickname";
String m_email="m_email";
String m_password="m_password";
}
public String sql(String SQL){
return Utility.getSQL組合字(SQL, MEMBER.fn.class);
}
public int clear() {
String SQL = "delete from MEMBER";
Object parameter[] = {};
return super.excuteUpdate(SQL, parameter);
}

public int delete(int memberid) {
String SQL = "delete from MEMBER where memberid=?";
Object parameter[] = {memberid};
return super.excuteUpdate(SQL, parameter);
}

public int update(String m_name,String m_phone,String m_nickname,String m_email,String m_password, int memberid){
String SQL = "update MEMBER set m_name=?,m_phone=?,m_nickname=?,m_email=?,m_password=? where memberid=?";
Object parameter[] = {m_name,m_phone,m_nickname,m_email,m_password,memberid};
return super.excuteUpdate(SQL,parameter);
}

public int insert(String m_name,String m_phone,String m_nickname,String m_email,String m_password){
String SQL = "insert into MEMBER(m_name,m_phone,m_nickname,m_email,m_password) values(?,?,?,?,?)";
Object parameter[] = { m_name,m_phone,m_nickname,m_email,m_password};
return super.excuteUpdate(SQL ,parameter);
}

public String[][] select() {
String SQL = "select * from MEMBER";
Object parameter[] = {};
return super.select(SQL, parameter);
}

public MEMBER[] select_Object() {
String SQL = "select * from MEMBER";
Object parameter[] = {};
String data[][] = super.select(SQL, parameter);MEMBER obj[] = toObject(data);return obj;}

public String[][] select( int memberid) {
String SQL = "select * from MEMBER where memberid=?";
Object parameter[] = {memberid};
return super.select(SQL, parameter);}

public MEMBER[] select_Object( int memberid) {
String data[][] = this.select(memberid);MEMBER obj[] = toObject(data);return obj;}

public int selectCount() {
String SQL = "select count(memberid) from MEMBER";
Object parameter[] = {};
String d[][] = super.select(SQL, parameter);
return Integer.parseInt(d[0][0]);}

public String[][] selectPage(int pageSize, int pageIndex, int rowCount) {
int desc = PaggingSQL.ASC;PaggingSQL ps = new dbTool.MySQL();String TABLE_NAME = fn.TABLE_NAME;String PK = fn.PK;String SQL = ps.getSelectPage(pageSize, pageIndex, TABLE_NAME, PK, desc, rowCount);Object parameter[] = {};
return super.select(SQL, parameter);
}
public String[][] selectPageOrderBy(int pageSize, int pageIndex, String sortName, int desc, int rowCount) {
PaggingSQL ps = new dbTool.MySQL();String TABLE_NAME = fn.TABLE_NAME;String PK = fn.PK;String SQL = ps.getSelectPageOrderBy(pageSize, pageIndex, TABLE_NAME, PK, sortName, desc, rowCount);Object parameter[] = {};
return super.select(SQL, parameter);
}
 /**
 * ����r where ���μg
 * @param pageSize
 * @param pageIndex
 * @param sortName
 * @param desc
 * @param rowCount
 * @param whereCondition = �ipk>0�j, ����r where ���μg
 * @return
 */
public String[][] selectPageOrderBy(int pageSize, int pageIndex, String sortName, int desc, int rowCount, String whereCondition) {
PaggingSQL ps = new dbTool.MySQL();String TABLE_NAME = fn.TABLE_NAME;String PK = fn.PK;
//�d��,����r where ���μg, ex:�ipk>0�j
String SQL = ps.getSelectPageOrderBy(pageSize, pageIndex, TABLE_NAME, PK, sortName, desc, rowCount, whereCondition);Object parameter[] = {};
return super.select(SQL, parameter);
}
public MEMBER[] selectPage_Object(int pageSize, int pageIndex, int rowCount) {
	String data[][] = this.selectPage(pageSize, pageIndex, rowCount);
	MEMBER obj[] = toObject(data);
	return obj;
}
 /**
 * ���ղέp����
 * @param fk_List
 * @return
 */
public Map<Integer, Integer> getGroupCount(String fkName, LinkedList<Integer> fk_List){String q = "";
Object parameter[] = new Object[fk_List.size()];
int i=0;
for (Integer no : fk_List) {
q += "?,";
parameter[i++] = no;
}
if (q.length() > 0){
q = q.substring(0, q.length()-1);
}
HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();String SQL = "";SQL += "SELECT "+ fkName +", count("+ fkName +") ";SQL += "FROM "+ fn.TABLE_NAME +" where "+fkName+" in (" + q + ")";SQL += "group by "+ fkName +";";String data[][] = super.select(SQL, parameter);for (int j = 0; j < data.length; j++) {int key = Integer.parseInt(data[j][0]);int count = Integer.parseInt(data[j][1]);map.put(key, count);}return map;} /**
 * Where PK in(?,?,?....)
 * @param idList
 * @return
 */
public Map<Integer, MEMBER> selectMap(LinkedList<Integer> idList){
String q = "";
Object parameter[] = new Object[idList.size()];
int i=0;
for (Integer no : idList) {
q += "?,";
parameter[i++] = no;
}
if (q.length() > 0){
q = q.substring(0, q.length()-1);
}
HashMap<Integer, MEMBER> map = new HashMap<Integer, MEMBER>();

String SQL = "select * from MEMBER where memberid in ("+ q +")";
String data[][] = super.select(SQL, parameter);
MEMBER[] obj = this.toObject(data);
for (MEMBER o : obj) {
map.put(new Integer(o.memberid) , o);
}
return map;
}
public MEMBER[] toObject(String data[][]){
MEMBER[] obj = new MEMBER[data.length];
for (int i = 0; i < obj.length; i++) {
obj[i] = new MEMBER(super.getSetting());obj[i].memberid=Integer.parseInt(data[i][0]);
obj[i].m_name=data[i][1];
obj[i].m_phone=data[i][2];
obj[i].m_nickname=data[i][3];
obj[i].m_email=data[i][4];
obj[i].m_password=data[i][5];
}
return obj;}
}